using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region DicItem

	/// <summary>
	/// DicItem object for NHibernate mapped table 'DicItem'.
	/// </summary>
	[Serializable]
	public class DicItem : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected string _dicItemKey;
		protected string _description;
		protected int _sort;
		protected bool _isDefault;
		protected bool _isEnabled;
		protected DicType _dicType;
		protected IList _meetingRoomLogisticalInfos;
		protected IList _templateTypeTemplates;
		protected IList _departmentTypeApplications;
		protected IList _actionPoints;
		protected IList _siteAppVisitingSites;
		protected IList _partnerTypeAPPartners;
		protected IList _departmentTypeDepartments;
		protected IList _accountTypeCustomerInfos;
		protected IList _affectsCustomerAttendees;
		protected IList _responsibilityCustomerAttendees;
		protected IList _attachmentTypeAttachments;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public DicItem() { }

		public DicItem( string dicItemKey, string description, int sort, bool isDefault, bool isEnabled, DicType dicType )
		{
			this._dicItemKey = dicItemKey;
			this._description = description;
			this._sort = sort;
			this._isDefault = isDefault;
			this._isEnabled = isEnabled;
			this._dicType = dicType;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public string DicItemKey
		{
			get { return _dicItemKey; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for DicItemKey", value, value.ToString());
				_dicItemKey = value;
			}
		}

		public string Description
		{
			get { return _description; }
			set
			{
				if ( value != null && value.Length > 250)
					throw new ArgumentOutOfRangeException("Invalid value for Description", value, value.ToString());
				_description = value;
			}
		}

		public int Sort
		{
			get { return _sort; }
			set { _sort = value; }
		}

		public bool IsDefault
		{
			get { return _isDefault; }
			set { _isDefault = value; }
		}

		public bool IsEnabled
		{
			get { return _isEnabled; }
			set { _isEnabled = value; }
		}

		public DicType DicType
		{
			get { return _dicType; }
			set { _dicType = value; }
		}

		public IList MeetingRoomLogisticalInfos
		{
			get
			{
				if (_meetingRoomLogisticalInfos==null)
				{
					_meetingRoomLogisticalInfos = new ArrayList();
				}
				return _meetingRoomLogisticalInfos;
			}
			set { _meetingRoomLogisticalInfos = value; }
		}

		public IList TemplateTypeTemplates
		{
			get
			{
				if (_templateTypeTemplates==null)
				{
					_templateTypeTemplates = new ArrayList();
				}
				return _templateTypeTemplates;
			}
			set { _templateTypeTemplates = value; }
		}

		public IList DepartmentTypeApplications
		{
			get
			{
				if (_departmentTypeApplications==null)
				{
					_departmentTypeApplications = new ArrayList();
				}
				return _departmentTypeApplications;
			}
			set { _departmentTypeApplications = value; }
		}

		public IList ActionPoints
		{
			get
			{
				if (_actionPoints==null)
				{
					_actionPoints = new ArrayList();
				}
				return _actionPoints;
			}
			set { _actionPoints = value; }
		}

		public IList SiteAppVisitingSites
		{
			get
			{
				if (_siteAppVisitingSites==null)
				{
					_siteAppVisitingSites = new ArrayList();
				}
				return _siteAppVisitingSites;
			}
			set { _siteAppVisitingSites = value; }
		}

		public IList PartnerTypeAPPartners
		{
			get
			{
				if (_partnerTypeAPPartners==null)
				{
					_partnerTypeAPPartners = new ArrayList();
				}
				return _partnerTypeAPPartners;
			}
			set { _partnerTypeAPPartners = value; }
		}

		public IList DepartmentTypeDepartments
		{
			get
			{
				if (_departmentTypeDepartments==null)
				{
					_departmentTypeDepartments = new ArrayList();
				}
				return _departmentTypeDepartments;
			}
			set { _departmentTypeDepartments = value; }
		}

		public IList AccountTypeCustomerInfos
		{
			get
			{
				if (_accountTypeCustomerInfos==null)
				{
					_accountTypeCustomerInfos = new ArrayList();
				}
				return _accountTypeCustomerInfos;
			}
			set { _accountTypeCustomerInfos = value; }
		}

		public IList AffectsCustomerAttendees
		{
			get
			{
				if (_affectsCustomerAttendees==null)
				{
					_affectsCustomerAttendees = new ArrayList();
				}
				return _affectsCustomerAttendees;
			}
			set { _affectsCustomerAttendees = value; }
		}

		public IList ResponsibilityCustomerAttendees
		{
			get
			{
				if (_responsibilityCustomerAttendees==null)
				{
					_responsibilityCustomerAttendees = new ArrayList();
				}
				return _responsibilityCustomerAttendees;
			}
			set { _responsibilityCustomerAttendees = value; }
		}

		public IList AttachmentTypeAttachments
		{
			get
			{
				if (_attachmentTypeAttachments==null)
				{
					_attachmentTypeAttachments = new ArrayList();
				}
				return _attachmentTypeAttachments;
			}
			set { _attachmentTypeAttachments = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is DicItem))
				throw new InvalidCastException("This object is not of type DicItem");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((DicItem)obj).Id);
					break;
				case "DicItemKey":
						relativeValue = ( this.DicItemKey != null ) ? this.DicItemKey.CompareTo(((DicItem)obj).DicItemKey) : -1;
					break;
				case "Description":
						relativeValue = ( this.Description != null ) ? this.Description.CompareTo(((DicItem)obj).Description) : -1;
					break;
				case "Sort":
						relativeValue = ( this.Sort != Convert.ToInt32( null) ) ? this.Sort.CompareTo(((DicItem)obj).Sort) : -1;
					break;
				case "IsDefault":
						relativeValue = ( this.IsDefault != Convert.ToBoolean( null) ) ? this.IsDefault.CompareTo(((DicItem)obj).IsDefault) : -1;				
					break;
				case "IsEnabled":
					relativeValue = this.IsEnabled.CompareTo(((DicItem)obj).IsEnabled);
					break;
                default:
                    goto case "Id";
			}
            if (DicItem.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
